package com.lecyon.farm.util;

import com.lecyon.farm.common.constant.CommonConstant;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * @author Yao Zheng
 * @Date 2019/10/24 19:44
 */
public class ShiroUtils {

    /**
     * 生成${GapConstant.SALT_VALUE_LENGTH}长度的随机盐值
     *
     * @return
     */
    public static String createSalt() {
        return RandomStringUtils.randomAlphanumeric(CommonConstant.SALT_VALUE_LENGTH);
    }

    /**
     * 加盐加密
     *
     * @param srcPassword 原始密码
     * @param saltValue   盐值
     * @return
     */
    public static String salt(Object srcPassword, String saltValue) {
        return new SimpleHash(CommonConstant.SALT_METHOD, srcPassword, saltValue, 1024).toString();
    }

}
